import { createRouter, createWebHistory } from 'vue-router'
// import { useUserStore } from '@/stores/user'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // { path: '/', redirect: '/' },
    // { path: '/login', meta: { title: '登录' }, component: () => import('../views/Login.vue') },
      //404 后来的页面
      // { path: '/404', name: 'NotFound', meta: { title: '404找不到页面' }, component: () => import('../views/404.vue') },
      // { path: '/:pathMatch(.*)', redirect: '/404' }
    {
      path: '/login',
      name: 'login',
      component: ()=>import('@/views/Login.vue')
    },
    // 404页面识别
    { path: '/404', name: 'NotFound', meta: { title: '404找不到页面' }, component: () => import('../views/404.vue') },
    { path: '/:pathMatch(.*)', redirect: '/404' },
    { path: '/', redirect: '/start' }, // 首页 展示页
    { path: '/start', name: 'start', component: ()=> import('@/views/Home.vue') },
    { path: '/safety_tip', name: 'safety_tip', component: ()=> import('@/views/Tip.vue') },
    { path: '/home', redirect: '/home/check' },
    {
      path: '/home',
      name: 'administrative',
      component:()=>import('@/views/administrative/Home.vue'),
      children: [
        { path: 'info', name: 'info', meta: { title: '成员信息' }, component: () => import('@/views/product/Info.vue') },
        { path: 'task', name: 'task', meta: { title: '任务' }, component: () => import('@/views/product/Task.vue') },
        { path: 'supervise-task', name: 'supervise-task', meta: { title: '监督任务' }, component: () => import('@/views/product/Supervise-task.vue') },
        { path: 'test', name: 'test', meta: { title: '测试' }, component: () => import('../views/product/Test.vue') },
        // 通讯------
        { path: 'communication', name: 'communication', meta: { title: '任务通知' }, component: () => import('@/views/interaction/Communication.vue') },
        { path: 'relation', name: 'relation', meta: { title: '联系' }, component: () => import('@/views/interaction/Relation.vue') },

        //it部门
        { path: 'it', name: 'it', meta: { title: '成员' }, component: () => import('@/views/it/It.vue') },
        { path: 'safety', name: 'safety', meta: { title: '安全政策' }, component: () => import('@/views/it/safety.vue') },

        //最高权限可以看到 所有人的做了什么
        {  path: 'log', name: 'log', meta: { title: '系统日志' }, component: () => import('@/views/log/Log.vue') },
        {  path: 'daily', name: 'dialy', meta: { title: '日报' }, component: () => import('@/views/daily/Daily.vue') },

    
         {
         path: 'publish',
       name: 'publishAnnouncement',
         component:()=>import('@/views/administrative/announcement/PublishAnAnnouncement.vue')
         },
         {
         path: 'details',
         name: 'announcementDetails',
         component:()=>import('@/views/administrative/announcement/AnnouncementDetails.vue')
         },{
          path: 'check',meta: { title: '公告' },
          name: 'checkOutTheAnnouncement',
          component:()=>import('@/views/administrative/announcement/CheckOutTheAnnouncement.vue')
        },
        {
          path: 'moreancts',
          name: 'moreAnnouncements',
          component:()=>import('@/views/administrative/announcement/MoreAnnouncements.vue')
        },
        {
          path: 'publish',
          name: 'publishAnnouncement',meta: { title: '上传公告' },
          component:()=>import('@/views/administrative/announcement/PublishAnAnnouncement.vue')
        },
        //详情
        {
          path: 'details',
          name: 'announcementDetails',
          component:()=>import('@/views/administrative/announcement/AnnouncementDetails.vue')
        },
        {
          path: 'announcementList',
          name: 'announcementList',meta: { title: '查看公告' },
          component:()=>import('@/views/administrative/announcement/AnnouncementList.vue')
        },
        {
          path: 'finance',
          name: 'finance',
          meta: { title: '收支统计' },
          component: ()=>import('@/views/finance/finance.vue')
        },
        {
          path: 'process',
          name: 'purchase-home',
          component:()=>import('@/views/purchase/process.vue')
        },
        {
          path: 'finance1',
          name: 'finance1',
          meta: { title: '扣款事项' },
          component: ()=>import('@/views/finance/Finance1.vue')
        },
        {
         path: 'supplier',
         name: 'purchase-supplier',
         component:()=>import('@/views/purchase/supplier.vue')
         },
         {
         path: 'order',
        name: 'purchase-order',
        component:()=>import('@/views/purchase/order.vue')
        },
        {
          path: 'warehouse',
          name: 'purchase-warehouser',
          component:()=>import('@/views/purchase/warehouse.vue')
        },
        {
          path: 'sale',
          name: 'sale',
          meta: { title: '查看客户' },
          component:()=>import('@/views/sale/sale.vue')
        },
        {path: 'hradd', name: 'hradd', meta: { title: '入职管理' }, component:()=>import('@/views/hrdepartment/hradd.vue')},
        {path: 'hrma', name: 'hrma', meta: { title: '人员信息' },   component:()=>import('@/views/hrdepartment/hrma.vue')},
        {path: 'shenpi', name: 'shenpi', meta: { title: '请假审批' }, component:()=>import('@/views/hrdepartment/shenpi.vue')},
        {path: 'hrpost', name: 'hrpost', meta: { title: '岗位调动' }, component:()=>import('@/views/hrdepartment/hrpost.vue')},
        {path: 'inter', name: 'inter', meta: { title: '离职管理' }, component:()=>import('@/views/hrdepartment/inter.vue')},
        {path: 'kaoqin', name: 'kaoqin',  meta: { title: '考勤打卡' },  component:()=>import('@/views/kaoqin/kaoqin.vue')},
        {path: 'kaoqinList', name: 'kaoqinList', meta: { title: '考勤记录' }, component:()=>import('@/views/kaoqin/kaoqinList.vue') },
        {path: 'kaoqinjia',  name: 'kaoqinjia', meta: { title: '我的请假' },  component:()=>import('@/views/kaoqin/kaoqinjia.vue')},
        {path: 'jilu', name: 'jilu', meta: { title:'假期记录'}, component:()=>import('@/views/kaoqin/jilu.vue')},
        {path: 'diaogang', name: 'diaogang',meta: { title:'调岗申请 '},component:()=>import('@/views/diaogang/diaogang.vue') },
        
        {path: 'diaogangshow', name: 'diaogangshow',meta: { title:'调岗信息'},component:()=>import('@/views/diaogang/diaogangshow.vue') },

          {
              path: 'source',
              name: 'source',
              component:()=>import('@/views/source/source1.vue')
          },
        {
          path: 'sale2',
          name: 'sale2',
          meta: { title:'销售管理'},
          component:()=>import('@/views/sale/sale2.vue')
        },
        
        
        {
          path: 'ReallyName',
          name: 'ReallyName',
          meta: { title:'实名认证'},
          component:()=>import('@/views/persondata/ReallyName.vue')
        },
        {
          path: 'zonghe',
          name: 'zonghe',
          meta: { title:'综合部门'},
          component:()=>import('@/views/zonghe/zonghe.vue') 
        },
        {
          path: 'Modifyavatar',
          name: 'Modifyavatar',
          meta: { title:'修改头像'},
          component:()=>import('@/views/persondata/Modifyavatar.vue') 
        },
        {
          path: 'ModifyPassword',
          name: 'ModifyPassword',
          meta: { title:'修改密码'},
          component:()=>import('@/views/persondata/ModifyPassword.vue') 
        },
        {
          path: 'financeTable',
          name: 'financeTable',
          component: ()=>import('@/views/finance/FinanceTable.vue')
        },
        {
              path: 'finance2',
              name: 'finance2',
              component: ()=>import('@/views/finance/Finance2.vue')
        },
        // 问题关键-----------------------
        {
          path: 'applicationApproval',
          name: 'applicationApproval',
          meta: { title:'申请审批'},
          component:()=>import('@/views/administrative/announcement/ApplicationApproval.vue')
        },
        {
          path: 'application',
          name: 'application',
          meta: { title:'申请审批'},
          component:()=>import('@/views/administrative/announcement/ApplicationForApproval.vue'),
          children: [
            {
              path: 'ap1',
              name: 'ap1',
              component:()=>import('@/views/administrative/announcement/application/Ap1.vue')
            },
            {
              path: 'xs1',
              name: 'xs1',
              component:()=>import('@/views/administrative/announcement/xs/Xs1.vue')
            },
            {
              path: 'weekend',
              name: 'weekend',
              component:()=>import('@/views/administrative/announcement/weekend/Weekend.vue')
            },
            {
              path: 'po1',
              name: 'po1',
              component:()=>import('@/views/administrative/announcement/purchaseOrder/Po1.vue')
            },
          ]
        },
        {
          path: 'edit',
          name: 'edit',
          meta: { title:'编辑'},
          component:()=>import('@/views/persondata/edit.vue')
        },
        {
          path: 'timeImport',
          name: 'timeImport',
          meta: { title: '收支统计' },
          component:()=>import('@/views/finance/TimeImportent.vue')
        },
        
      ]
    },

  ],
})

let hasRefreshed = false; // 添加一个是否刷新过的标志位


// 网页标题
router.beforeEach((to, from, next) => {
  if (to.query.topic) {
    document.title = `${to.query.topic}`;
  }else{
    document.title = to.meta.title || 'NO-Title'
  }
  next()
})


// 登录访问拦截
// router.beforeEach((to) => {
//   const userStore = useUserStore()
//   if (!userStore.token && to.path !== '/login') return '/login'
// })
export default router
